import BaseController from "./base.js";
/**
 * 后台首页相关接口
 */
export default class extends BaseController {
    /**
    * 数据统计 
    *
    * @returns {Promise} 项目数据统计
    * @example
    *
    * const data = await request.post("/api/admin/home/run");
    *  返回对象包含以下属性：
    * {
    *   "errno": 0,
    *   "errmsg": "",
    *   "data": {
    *     "userNum": 22,
    *     "firstHouseNum": 2,
    *     "secondHouseNum": 20,
    *     "rentalNum": 20
    *   }
    * }
    */
   async runAction(){
        //定义变量保存要返回的数据
        let data = {};

        //获取用户数量
        let userNum = await this.model("users")
        .count();
        data['userNum'] = userNum;

        //获取新房数量
        let firstHouseNum = await this.model("firsthouse")
        .count();
        data['firstHouseNum'] = firstHouseNum;

        //获取旧房数量
        let secondHouseNum = await this.model("secondhouse")
        .count();
        data['secondHouseNum'] = secondHouseNum;

        //获取出租房数量
        let rentalNum = await this.model("rental")
        .count();
        data['rentalNum'] = rentalNum;

        // 返回数据
        return this.success(data);
   }
}